<template>
  <div ref="appContainer" class="app-container home-bg-padding">
    <CustomSearch
      ref="searchForm"
      :show-all.sync="showAll"
      :show-input="false"
      @search="searchFn"
      @reset="resetFn"
      @calHeight="calHeight"
    >
      <template #select>
        <sec-form-item prop="roleName">
          <sec-select v-model="searchForm.roleName" placeholder="角色名称">
            <sec-option
              v-for="(item, index) in tableData"
              :key="index"
              :label="item.roleName"
              :value="item.roleId"
            >
            </sec-option>
          </sec-select>
        </sec-form-item>
      </template>
    </CustomSearch>
    <sec-table :data="tableData" size="mini" style="width: 100%">
      <sec-table-column type="index" label="序号" width="200">
      </sec-table-column>
      <sec-table-column prop="roleName" label="角色名称" width="200" />

      <sec-table-column prop="count" label="用户数" width="120">
      </sec-table-column>
      <sec-table-column
        prop="roleDesc"
        label="角色描述"
        :show-overflow-tooltip="true"
      >
      </sec-table-column>
      <sec-table-column prop="createTime" label="创建时间" width="220">
      </sec-table-column>
      <sec-table-column
        fixed="right"
        label="操作"
        width="88"
        label-class-name="operate-column"
      >
        <template slot-scope="scope">
          <sec-button type="text" size="small" @click="onDetail(scope.row)">
            详情
          </sec-button>

          <span :style="{ color: '#f1f1f1', padding: '0 5px' }">|</span>
          <sec-button
            type="text"
            size="small"
            :style="
              scope.row.processStatus == 5 || scope.row.processStatus == 1
                ? {
                    color: '#999',
                    pointerEvents: 'none',
                    cursor: 'normal'
                  }
                : { color: '#537af0' }
            "
            @click="onHandle(scope.row)"
          >
            编辑
          </sec-button>
        </template>
      </sec-table-column>
    </sec-table>

    <Detail :row-data="rowData" :detail-visible.sync="detailVisible"> </Detail>
    <Edite
      :row-data="rowData"
      :edite-visible.sync="editeVisible"
      @updateList="getList"
    >
    </Edite>
  </div>
</template>

<script>
import Detail from './componets/detail.vue'
import Edite from './componets/edite.vue'
import http from '@/utils/http'
import pagination from '@/utils/mixins/pagination'
import CustomSearch from '@/components/CustomSearch'
export default {
  components: { Detail, Edite, CustomSearch },
  mixins: [pagination],
  data() {
    return {
      tableData: [
        {
          role: '超级管理员',
          count: 2,
          desc: '管理员拥有平台最大的管理权限，在查看、操作平台功能的基础上还可以创建用户、并为其分配相应的角色。',
          time: '2023-04-01 19:37:22'
        },
        {
          role: '审计员',
          count: 4,
          desc: '审计员对所有用户的内容创建、编辑的数据拥有审计、查看的权限。',
          time: '2023-04-01 19:37:22'
        },
        {
          role: '安全员',
          count: 13,
          desc: '作为平台安全管理的运营人员可以查看平台的事件、资产等信息，并根据运营需要进行策略的配置及事件的处理。',
          time: '2023-04-01 19:37:22'
        }
      ],
      rowData: {},
      detailVisible: false,
      editeVisible: false,
      searchForm: {},
      showAll: true
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList(
      params = {
        _updatedAt: Date.now()
      }
    ) {
      this.loadingControl(['case1'], true)
      http
        .roleList(params)
        .then(({ data }) => {
          this.loadingControl(['case1'], false)
          this.tableData = data
        })
        .catch(() => {
          this.loadingControl(['case1'], false)
        })
    },
    onDetail(row) {
      this.rowData = row
      this.detailVisible = true
    },
    onHandle(row) {
      this.rowData = row
      this.editeVisible = true
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  display: flex;
  align-items: center;
  flex-direction: column;
  flex-wrap: wrap;
  align-items: stretch;
  flex-grow: 1;
  padding: 16px;
  background-color: #fff;
  margin: 20px;
  padding: 20px;
  .toolbar {
    display: flex;
    justify-content: flex-end;
    background-color: #fff;
    margin: 20px 0 30px 0;
    column-gap: 10px;
    .el-button + .el-button {
      margin-left: 0;
    }
  }
}
</style>
